<script setup>
import { ref, computed } from 'vue'
import { showToast } from 'vant';
import { checkTelFn } from '@/api/register';
import { useRouter } from 'vue-router';

const router = useRouter()
const tel = ref('')
const flag = computed(() => {
    return /^(?:(?:\+|00)86)?1[3-9]\d{9}$/.test(tel.value) != true
})

function onSubmit() {
    checkTelFn({
        tel: tel.value
    }).then(res => {
        // console.log(res);
        showToast(res.message)
        // console.log(registerInfo.registerInfo);
        if (res.data.checked) {
            router.push('/register/step2')
        }
    })
}
</script>
<template>
    <van-form @submit="onSubmit">
        <van-cell-group inset>
            <van-field v-model="tel" name="手机号" label="手机号" placeholder="请输入手机号"
                :rules="[{ required: true, message: '请填写手机号' }]" />
        </van-cell-group>
        <div style="margin: 16px;">
            <van-button round block type="danger" native-type="submit" :disabled="flag">
                下一步
            </van-button>
        </div>
    </van-form>
</template>